// components/activity/activity-base-view/index.js
import componentBehavior from '../../../behaviors/component';
import { COMPONENT_OPTIONS } from '../../../constants/common';
import { isEmpty, getTimeBeginEnd } from '../../../common/utils';

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        type: {
            type: String,
            value: 'detail', // detail || preview
        },
        activityInfo: {
            type: Object,
            value: {},
        },
    },
    observers: {
        'activityInfo': function (val) {
            if (val && !isEmpty(val)) {
                const { intro = [], begined, ended } = val;
                const introInfo = intro.map(i => {
                    if (i.type === 'pic_list') {
                        i.resource = i.resource ? i.resource.split(',') : [];
                    }
                    return i;
                });
                const dateStr = getTimeBeginEnd(begined, ended);
                this.setData({ introInfo, dateStr });
            }
        },
    },
    data: {
        dateStr: '',
        introInfo: [],
    },
    methods: {
    }
})
